﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Procedure = DeltaFlex.Data.ConsProcedures.Articles;

namespace DeltaFlex.Data
{
    public class Article
    {
        public Article()
        { }

        #region Insertar
        public static int InsertarArticle(string referencia, string nom, string unitats, decimal pvp)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_INSERTAR_ARTICLE;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_REFERENCIA, referencia);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_NOM, nom);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_UNITAT, unitats);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_PVP, pvp);

            return Operacions_BD.Insertar(cmd);
        }
        #endregion

        #region Selects
        /// <summary>
        /// Llista el cataleg d'articles
        /// </summary>
        /// <returns>Retorna una llista amb tots els articles</returns>
        public static IDataReader LlistaTotsArticles()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = Procedure.SP_CERCART_TOTS_ARTICLES;
            cmd.CommandType = CommandType.StoredProcedure;

            return Operacions_BD.Reader(cmd);
        }

        public static IDataReader LlistarArticleByIdArticle(int idArticle)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_CERCAR_ARTICLE_BY_IDARTICLE;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDARTICLE, idArticle);

            return Operacions_BD.Reader(cmd);
        }

        #endregion

    }
}
